﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/CSS/V3/style.css?v=2.2.0" rel="stylesheet">
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet"> 
    <link href="/CSS/V3/BaseClassV3.css" rel="stylesheet" />
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/JqueryPlug/laypage/laypage.js"></script> 
    <script src="/Scripts/avalon.min.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <style>
        #menuline {
         border-bottom:1px solid #95EAE2;
        }
        ul li {
        line-height:35px;
        height:40px;
        }
    </style>
    <script>

        var model = avalon.define({
            $id: "CommonData",
            CommonData: [],
            SearchContent: "",
            selMenu: 0,
            ReadCount: 0,
            NoReadCount: 0,
            allStatus: 'Y',
            GetXXZXDataList: function (msgType) {
                model.selMenu = (msgType == "Y" ? 1 : 0);
                model.allStatus = (msgType == "Y" ? "N" : "Y");
                model.ModityBtn(msgType, $("#btnModify"));
                $.getJSON('/API/FTAPI.ashx?Action=GETXXZXIST_PAGE', { P1: msgType, P2: model.SearchContent, p: 1 }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.CommonData = resultData.Result;
                        laypage({
                            cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                            pages: Math.ceil(parseInt(resultData.Result1) * 1.0 / 8), //通过后台拿到的总页数
                            curr: 1, //初始化当前页
                            jump: function (e) { //触发分页后的回调

                                $.getJSON('/API/FTAPI.ashx?Action=GETXXZXIST_PAGE', { P1: msgType, P2: model.SearchContent, p: e.curr }, function (resultData) {
                                    model.CommonData = resultData.Result;
                                })
                            }
                        });
                    }
                })
                model.GETXXCOUNT();

            }, ReadXX: function (item, dom, status) {

                var Ids = "";
                if (item == null && $(".iconfont").length == 0) {
                    return;//如果是标记本页状态，消息数量必须大于0
                }
                if (item == null && $(".iconfont").length > 0) {
                    $(".iconfont").each(function () {
                        Ids += $(this).prop("id") + ",";
                    })
                    Ids = Ids.length > 1 ? Ids.substring(0, Ids.length - 1) : Ids;
                }

                $.post("/API/FTAPI.ashx", { Action: "UPDTEREADSTATES", P1: item == null ? Ids : item.ID, s: status }, function (result) {
                    var jsonresult = $.parseJSON(result)
                    if ($.trim(jsonresult.ErrorMsg) != "") {
                        parent.ComFunJS.winwarning(jsonresult.ErrorMsg);
                    } else { 
                        if (item == null) {
                            model.ModityBtn(status, dom); 
                            model.allStatus = model.allStatus == "Y" ? "N" : "Y";
                            model.CommonData.forEach(function (val) {
                                val.isRead = status;
                            })
                        } else { 
                            item.isRead = status;
                        }
                        if (item != null) {
                            model.OpenDetail(item);
                        }
                        model.GETXXCOUNT();
                    }
                })
            },
            OpenDetail: function (item) {
                if (item.MsgLink) {
                    parent.ComFunJS.winviewform(item.MsgLink, "查看数据", "1000", "");
                }
            },
            GETXXCOUNT: function () {
                $.getJSON('/API/FTAPI.ashx?Action=GETXXCOUNT', function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.NoReadCount = resultData.Result;
                        model.ReadCount = resultData.Result1;
                    }
                })
            }, ModityBtn: function (status, dom) {
                var removeClass = " btn-white";
                var addClass = "btn-success";
                $(dom).text("标记本页消息为" + (status == "Y" ? "未" : "已") + "读").removeClass(status == "Y" ? addClass : removeClass).addClass(status == "Y" ? removeClass : addClass);
            }
        });
        avalon.ready(function () {
            model.GetXXZXDataList("N");
            model.GETXXCOUNT();
        })

    </script>

</head>
<body class="gray-bg" ms-controller="CommonData">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-content mailbox-content">
                        <div class="file-manager">
                            <div class="space-25"></div>
                            <h5>消息中心</h5>
                            <ul class="folder-list m-b-md" style="padding: 0">
                                <li ms-attr-id="model.selMenu==0?'menuline':''" >
                                    <a href="javascript:void(0)" ms-click="GetXXZXDataList('N')" style="padding:10px 0px;">
                                        <i class="fa fa-inbox "></i> 未读消息 <span class="label label-warning pull-right">{{NoReadCount}}</span>
                                    </a>
                                </li>
                                <li ms-attr-id="model.selMenu==1?'menuline':''">
                                    <a href="javascript:void(0)" style="padding:10px 0px;" ms-click="GetXXZXDataList('Y')"> <i class="fa fa-envelope-o"></i> 已读消息<span class="label label-warning pull-right">{{ReadCount}}</span></a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-9 animated fadeInRight">
                <div style="margin-bottom:10px;">
                    <h2>
                        消息中心
                    </h2>
                    <div class="mail-tools tooltip-demo m-t-md">
                        <div class="btn-group pull-right">
                            <div id="pageDiv" class="text-right"></div>
                            </div>
                            <button class="btn btn-sm" id="btnModify" ms-click="ReadXX(null,this,allStatus)" data-toggle="tooltip" data-placement="top" title="标为已读">
                                <i class="fa fa-eye"></i>标记本页为已读
                            </button>
                        </div>
                </div>
                <div class="mail-box">
                    <table class="table table-hover table-mail">
                        <tbody>
                            <tr class="unread">
                                <td class="check-mail">
                                    #
                                </td>
                                <td class="mail-ontact">
                                    <a href="mail_detail.html">消息类别</a>
                                </td>
                                <td class="mail-subject">
                                    <a href="mail_detail.html">内容</a>
                                </td>
                                <td class="text-right mail-date">时间</td>
                            </tr>
                            <tr class="nread" ms-repeat-item="CommonData">
                                <td class="check-mail">
                                    <i ms-click="ReadXX(item,this,item.isRead=='N'?'Y':'N')" ms-attr-id="item.ID" class="iconfont" ms-class-1="icon-weigouxuan:item.isRead=='N'" ms-class-2="icon-gouxuan:item.isRead=='Y'" style="font-size:18px;vertical-align: sub;"></i> 
                                </td>
                                <td class="mail-ontact">
                                    {{item.MsgType}}
                                </td>
                                <td class="mail-subject">
                                    <a ms-click="ReadXX(item,$(this).parent().find('i'),'Y')">{{item.MsgContent}}</a>
                                </td>
                                <td class="text-right mail-date">{{item.CRDate|date("yyyy-MM-dd")}}</td>
                            </tr>

                        </tbody>
                    </table>

                </div>
            </div>
        </div>
    </div>
</body>
</html> 